<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    xmlns:local="clr-namespace:PropertyTools.Wpf"
                    xmlns:chrome="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">

    <Geometry x:Key="DownArrowGeometry">M 0 0 L 3.5 4 L 7 0 Z</Geometry>
    <Geometry x:Key="UpArrowGeometry">M 0 4 L 3.5 0 L 7 4 Z</Geometry>

    <LinearGradientBrush x:Key="ButtonNormalBackground" StartPoint="0,0" EndPoint="0,1">
        <LinearGradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#F3F3F3" Offset="0"/>
                <GradientStop Color="#EBEBEB" Offset="0.5"/>
                <GradientStop Color="#DDDDDD" Offset="0.5"/>
                <GradientStop Color="#CDCDCD" Offset="1"/>
            </GradientStopCollection>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="ButtonMouseOverBackground" StartPoint="0,0" EndPoint="0,1">
        <LinearGradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#FFEAF6FD" Offset="0"/>
                <GradientStop Color="#FFD9F0FC" Offset="0.50"/>
                <GradientStop Color="#FFBEE6FD" Offset="0.50"/>
                <GradientStop Color="#FFA7D9F5" Offset="1"/>
            </GradientStopCollection>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="ButtonPressedBackground" StartPoint="0.5,0" EndPoint="0.5,1">
        <LinearGradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#C2E4F6" Offset="0.5"/>
                <GradientStop Color="#ABDAF3" Offset="0.5"/>
                <GradientStop Color="#90CBEB" Offset="1"/>
            </GradientStopCollection>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>

    <Style x:Key="SpinButtonStyle" TargetType="{x:Type RepeatButton}">
        <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ButtonBase}">
                    <Grid>
                        <Border x:Name="Border" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" 
                                Background="{TemplateBinding Background}"/>
                        <ContentPresenter x:Name="Content" Margin="{TemplateBinding Padding}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          RecognizesAccessKey="True"
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" TargetName="Border" Value="{StaticResource ButtonMouseOverBackground}"/>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="Background" TargetName="Border" Value="{StaticResource ButtonPressedBackground}"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Opacity" TargetName="Content" Value="0.5"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <LinearGradientBrush x:Key="TextBoxBorder"
                         StartPoint="0,0"
                         EndPoint="0,20"
                         MappingMode="Absolute">
        <LinearGradientBrush.GradientStops>
            <GradientStop Color="#ABADB3" Offset="0.05"/>
            <GradientStop Color="#E2E3EA" Offset="0.07"/>
            <GradientStop Color="#E3E9EF" Offset="1"/>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>

    <Style TargetType="{x:Type local:SpinControl}">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="IsTabStop" Value="True" />
        <Setter Property="BorderBrush" Value="{StaticResource TextBoxBorder}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Padding" Value="0" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="UpButtonGeometry" Value="{StaticResource UpArrowGeometry}"/>
        <Setter Property="DownButtonGeometry" Value="{StaticResource DownArrowGeometry}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:SpinControl}">
                    <chrome:ListBoxChrome x:Name="Bd"
                                         BorderThickness="{TemplateBinding BorderThickness}"
                                         BorderBrush="{TemplateBinding BorderBrush}"
                                         Background="{TemplateBinding Background}"
                                         RenderMouseOver="{TemplateBinding IsMouseOver}"
                                         RenderFocused="{TemplateBinding IsKeyboardFocusWithin}"
                                         SnapsToDevicePixels="true">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="{TemplateBinding SpinButtonWidth}"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="1*"/>
                                <RowDefinition Height="1*"/>
                            </Grid.RowDefinitions>
                            <ContentPresenter Grid.RowSpan="2" Grid.ColumnSpan="1" Focusable="False" 
                                              Margin="{TemplateBinding Padding}" 
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                            <RepeatButton x:Name="PART_UP" Grid.Column="1" Style="{StaticResource SpinButtonStyle}" Margin="0" Interval="{TemplateBinding RepeatInterval}">
                                <Path Fill="{TemplateBinding Foreground}" Data="{TemplateBinding UpButtonGeometry}"/>
                            </RepeatButton>
                            <RepeatButton x:Name="PART_DOWN" Grid.Column="1" Grid.Row="1" Style="{StaticResource SpinButtonStyle}" Padding="0" Interval="{TemplateBinding RepeatInterval}">
                                <Path Fill="{TemplateBinding Foreground}" Data="{TemplateBinding DownButtonGeometry}"/>
                            </RepeatButton>
                        </Grid>
                    </chrome:ListBoxChrome>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="Bd" Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
